package com.softaria.spkiller.metadata;



public class ClassIdentifierImpl implements ClassIdentifier {

	private String className;
	
	public ClassIdentifierImpl(String className) {
		super();
		this.className = className;
	}

	public ClassIdentifierImpl() {
	}

	@Override
	public String getClassName() {
		return className;
	}


	public void setClassName(String className) {
		this.className = className;
	}

	@Override
	public int hashCode() {
		if(className==null) {
			return super.hashCode();
		}
		else {
			return className.hashCode();
		}
	}

	@Override
	public boolean equals(Object obj) {
		if(className==null) {
			return false;
		}
		else {
			if(obj instanceof ClassIdentifier) {
				ClassIdentifier other  = (ClassIdentifier)obj;
				return className.equals(other.getClassName());
			}
			else {
				return false;
			}
		}
	}

	@Override
	public String toString() {
		return "class: "+className;
	}

	@Override
	public String getPackageName() {
		int index = className.lastIndexOf('.');
		
		
		return index==-1?"":className.substring(0,index);
	}

	@Override
	public boolean matchesPath(String path) {
		
		String myPath = getPath();
		
		String theirPath = path.replaceAll("\\\\", "/");
		
		return myPath.equalsIgnoreCase(theirPath);
	}

	@Override
	public String getPath() {
		return className.replaceAll("\\.","/")+".class";
	}
	
	

}
